﻿<UserControl x:Class="MediaBrowser.Gui.Views.PageBooksView"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:ViewModel="clr-namespace:MediaBrowser.Gui.ViewModels"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
    xmlns:EffectsLib="clr-namespace:EffectsLib;assembly=EffectsLib"
    xmlns:MediaBrowser_Controls="clr-namespace:MediaBrowser.CustomControls;assembly=MediaBrowser.CustomControls"	
    xmlns:MitsuControls="clr-namespace:WPFMitsuControls;assembly=WPFMitsuControls"
    xmlns:Converters="clr-namespace:MediaBrowser.Gui.Converters"
    xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity" 
    xmlns:julmar="http://www.julmar.com/wpfhelpers"
    xmlns:Views="clr-namespace:MediaBrowser.Gui.Views"
    mc:Ignorable="d" d:DesignWidth="640" d:DesignHeight="480">

    <!--<UserControl.DataContext>
        <Binding Mode="OneWay" Path="Settings" Source="{StaticResource Locator}"/>
    </UserControl.DataContext>-->

    <UserControl.Resources>
        <ViewModel:ViewModelLocator x:Key="Locator" d:IsDataSource="True"/>
        <Converters:StringToBitmapConverter x:Key="stringToBitmapConverter" />

        <Storyboard x:Key="ShowCtrlAdminBooks" AccelerationRatio="0.5" DecelerationRatio="0.5" >
            <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="UserCtrlAdminBooks" 
                                           Storyboard.TargetProperty="(UIElement.Opacity)">
                <SplineDoubleKeyFrame KeyTime="00:00:00" Value="0"/>
                <SplineDoubleKeyFrame KeyTime="00:00:01" Value="1"/>
            </DoubleAnimationUsingKeyFrames>
            <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="UserCtrlAdminBooks" Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[0].(ScaleTransform.ScaleX)">
                <SplineDoubleKeyFrame KeyTime="00:00:00" Value="0"/>
                <SplineDoubleKeyFrame KeyTime="00:00:01" Value="1"/>
            </DoubleAnimationUsingKeyFrames>
            <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="UserCtrlAdminBooks" Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[0].(ScaleTransform.ScaleY)">
                <SplineDoubleKeyFrame KeyTime="00:00:00" Value="0"/>
                <SplineDoubleKeyFrame KeyTime="00:00:01" Value="1"/>
            </DoubleAnimationUsingKeyFrames>
            <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="UserCtrlAdminBooks" Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[3].(TranslateTransform.X)">
                <SplineDoubleKeyFrame KeyTime="00:00:00" Value="0"/>
                <SplineDoubleKeyFrame KeyTime="00:00:01" Value="1"/>
            </DoubleAnimationUsingKeyFrames>
            <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="UserCtrlAdminBooks" Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[3].(TranslateTransform.Y)">
                <SplineDoubleKeyFrame KeyTime="00:00:00" Value="0"/>
                <SplineDoubleKeyFrame KeyTime="00:00:01" Value="1"/>
            </DoubleAnimationUsingKeyFrames>
            <BooleanAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="Grp_Left" Storyboard.TargetProperty="(UIElement.IsEnabled)">
                <DiscreteBooleanKeyFrame KeyTime="00:00:01" Value="False"/>
            </BooleanAnimationUsingKeyFrames>
            <BooleanAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="Grp_Center" Storyboard.TargetProperty="(UIElement.IsEnabled)">
                <DiscreteBooleanKeyFrame KeyTime="00:00:01" Value="False"/>
            </BooleanAnimationUsingKeyFrames>
            <DoubleAnimation BeginTime="00:00:00" From="0"  To="-0.5" Duration="00:00:00.25"  
                                             Storyboard.TargetName="Grp_Left" 
                                             Storyboard.TargetProperty="(UIElement.Effect).(EffectsLib:BrightContrastEffect.Contrast)"/>
            <DoubleAnimation BeginTime="00:00:00" From="0"  To="-0.5" Duration="00:00:00.25"  
                                             Storyboard.TargetName="Grp_Center" 
                                             Storyboard.TargetProperty="(UIElement.Effect).(EffectsLib:BrightContrastEffect.Contrast)"/>
        </Storyboard>

        <Storyboard x:Key="HideCtrlAdminBooks" AccelerationRatio="0.5" DecelerationRatio="0.5" >
            <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="UserCtrlAdminBooks" 
                                           Storyboard.TargetProperty="(UIElement.Opacity)">
                <SplineDoubleKeyFrame KeyTime="00:00:00" Value="1"/>
                <SplineDoubleKeyFrame KeyTime="00:00:01" Value="0"/>
            </DoubleAnimationUsingKeyFrames>
            <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="UserCtrlAdminBooks" Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[0].(ScaleTransform.ScaleX)">
                <SplineDoubleKeyFrame KeyTime="00:00:00" Value="1"/>
                <SplineDoubleKeyFrame KeyTime="00:00:01" Value="0"/>
            </DoubleAnimationUsingKeyFrames>
            <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="UserCtrlAdminBooks" Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[0].(ScaleTransform.ScaleY)">
                <SplineDoubleKeyFrame KeyTime="00:00:00" Value="1"/>
                <SplineDoubleKeyFrame KeyTime="00:00:01" Value="0"/>
            </DoubleAnimationUsingKeyFrames>
            <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="UserCtrlAdminBooks" Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[3].(TranslateTransform.X)">
                <SplineDoubleKeyFrame KeyTime="00:00:00" Value="1"/>
                <SplineDoubleKeyFrame KeyTime="00:00:01" Value="0"/>
            </DoubleAnimationUsingKeyFrames>
            <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="UserCtrlAdminBooks" Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[3].(TranslateTransform.Y)">
                <SplineDoubleKeyFrame KeyTime="00:00:00" Value="1"/>
                <SplineDoubleKeyFrame KeyTime="00:00:01" Value="0"/>
            </DoubleAnimationUsingKeyFrames>
            <BooleanAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="Grp_Left" Storyboard.TargetProperty="(UIElement.IsEnabled)">
                <DiscreteBooleanKeyFrame KeyTime="00:00:01" Value="True"/>
            </BooleanAnimationUsingKeyFrames>
            <BooleanAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="Grp_Center" Storyboard.TargetProperty="(UIElement.IsEnabled)">
                <DiscreteBooleanKeyFrame KeyTime="00:00:01" Value="True"/>
            </BooleanAnimationUsingKeyFrames>
            <DoubleAnimation BeginTime="00:00:00" From="-0.5"  To="-0" Duration="00:00:00.25"  
                                             Storyboard.TargetName="Grp_Left" 
                                             Storyboard.TargetProperty="(UIElement.Effect).(EffectsLib:BrightContrastEffect.Contrast)"/>
            <DoubleAnimation BeginTime="00:00:00" From="-0.5"  To="-0" Duration="00:00:00.25"  
                                             Storyboard.TargetName="Grp_Center" 
                                             Storyboard.TargetProperty="(UIElement.Effect).(EffectsLib:BrightContrastEffect.Contrast)"/>
        </Storyboard>



        <Storyboard x:Key="HideGrpLeft" AccelerationRatio="0.5" DecelerationRatio="0.5">
            <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="Grp_Left" Storyboard.TargetProperty="(FrameworkElement.Width)">
                <SplineDoubleKeyFrame KeyTime="00:00:00.6000000" Value="0"/>
            </DoubleAnimationUsingKeyFrames>
            <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="Grp_Left" Storyboard.TargetProperty="(UIElement.Opacity)">
                <SplineDoubleKeyFrame KeyTime="00:00:00.6000000" Value="0.5"/>
            </DoubleAnimationUsingKeyFrames>
        </Storyboard>
        <Storyboard x:Key="ShowGrpLeft" AccelerationRatio="0.5" DecelerationRatio="0.5">
            <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="Grp_Left" Storyboard.TargetProperty="(FrameworkElement.Width)">
                <SplineDoubleKeyFrame KeyTime="00:00:00.6000000" Value="180"/>
            </DoubleAnimationUsingKeyFrames>
            <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="Grp_Left" Storyboard.TargetProperty="(UIElement.Opacity)">
                <SplineDoubleKeyFrame KeyTime="00:00:00.6000000" Value="1"/>
            </DoubleAnimationUsingKeyFrames>
        </Storyboard>
    </UserControl.Resources>
    <UserControl.Triggers>
        <EventTrigger RoutedEvent="Mouse.PreviewMouseDown" SourceName="zoomIn">
            <BeginStoryboard Storyboard="{StaticResource HideGrpLeft}"/>
        </EventTrigger>
        <EventTrigger RoutedEvent="Mouse.PreviewMouseDown" SourceName="zoomOut">
            <BeginStoryboard x:Name="ShowGrpLeft_BeginStoryboard" Storyboard="{StaticResource ShowGrpLeft}"/>
        </EventTrigger>
        <EventTrigger RoutedEvent="ButtonBase.Click" SourceName="btAdd">
            <BeginStoryboard Storyboard="{StaticResource ShowCtrlAdminBooks}"/>
        </EventTrigger>
        <EventTrigger RoutedEvent="ButtonBase.Click" SourceName="btUp">
            <BeginStoryboard Storyboard="{StaticResource ShowCtrlAdminBooks}"/>
        </EventTrigger>
        <EventTrigger RoutedEvent="Views:UserCtrlAdminBooks.OnClose" SourceName="UserCtrlAdminBooks">
            <BeginStoryboard Storyboard="{StaticResource HideCtrlAdminBooks}"/>
        </EventTrigger>
    </UserControl.Triggers>

    <Grid DataContext="{Binding Mode=OneWay, Path=Books, Source={StaticResource Locator}}">
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="Auto"/>
            <ColumnDefinition Width="*"/>
        </Grid.ColumnDefinitions>

        <!-- LEFT -->
        <GroupBox Grid.Column="0" x:Name="Grp_Left"
                  HorizontalContentAlignment="Stretch"
                  VerticalContentAlignment="Stretch"
                  Height="Auto" Margin="10,10,10,10" Width="180" >
            <GroupBox.Effect>
                <EffectsLib:BrightContrastEffect/>
            </GroupBox.Effect>
            <GroupBox.Header>
                <Label Foreground="WhiteSmoke" 
				  		FontSize="9" 
						FontWeight="Bold">
                    Liste des Livres
                </Label>
            </GroupBox.Header>
            <Grid>

                <Grid.RowDefinitions>
                    <RowDefinition Height="30"/>
                    <RowDefinition Height="*"/>
                    <RowDefinition Height="30"/>
                </Grid.RowDefinitions>

                <StackPanel x:Name="bd"
                    Grid.Row="0"
                    Orientation="Horizontal"
                    HorizontalAlignment="Stretch"
                    VerticalAlignment="Center">
                    <TextBox x:Name="tbSearch" Width="150"
                     Text="{Binding MediaLookFor, UpdateSourceTrigger=PropertyChanged, Mode=OneWayToSource}" />
                </StackPanel>

                <ListBox Name="lMedias" SelectionMode="Extended" ItemsSource="{Binding Medias}" 
                         Grid.Row="1" IsSynchronizedWithCurrentItem="True"  Background="{x:Null}"
                         HorizontalContentAlignment="Stretch">
                    <ListBox.ItemTemplate>
                        <DataTemplate>
                            <TextBlock Background="{x:Null}" Text="{Binding Name}" ToolTip="{Binding Name}" Width="151.887"/>
                        </DataTemplate>
                    </ListBox.ItemTemplate>
                </ListBox>

                <Grid Grid.Row="2">
                    <StackPanel Orientation="Horizontal" HorizontalAlignment="Right" >
                        <MediaBrowser_Controls:ImageButton x:Name="btAdd" Command="{Binding PrepareAddBookCommand}" Source="/MediaBrowser.Gui;Component/Images/book_add.png" Height="20" Margin="0,0,5,0" ToolTip="Ajouter un Livre"/>
                        <MediaBrowser_Controls:ImageButton x:Name="btUp" Command="{Binding PrepareUpdateBookCommand}" Source="/MediaBrowser.Gui;Component/Images/book_edit.png" Height="20" Margin="0,0,5,0" ToolTip="Modifier un Livre"/>
                        <MediaBrowser_Controls:ImageButton Command="{Binding DeleteBookCommand}" Source="/MediaBrowser.Gui;Component/Images/book_delete.png" Height="20" Margin="0,0,1,0" ToolTip="Supprimer un Livre"/>
                    </StackPanel>
                </Grid>
            </Grid>
        </GroupBox>
        <!-- END LEFT -->

        <!-- CENTER -->
        <GroupBox Grid.Column="1" Grid.Row="0" x:Name="Grp_Center"
                  HorizontalContentAlignment="Stretch"
                  VerticalContentAlignment="Stretch"
                  VerticalAlignment="Stretch"  Height="Auto" Margin="10,10,10,10">
            <GroupBox.Effect>
                <EffectsLib:BrightContrastEffect/>
            </GroupBox.Effect>
            <GroupBox.Header>
                <Label Foreground="WhiteSmoke" 
				  		FontSize="9" 
						FontWeight="Bold">
                    Navigation
                </Label>
            </GroupBox.Header>
            <Grid Margin="0,10,0,0">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="30" />
                    <ColumnDefinition Width="*" />
                    <ColumnDefinition Width="30" />
                </Grid.ColumnDefinitions>

                <Grid.RowDefinitions>
                    <RowDefinition Height="*" />
                    <RowDefinition Height="30" />
                </Grid.RowDefinitions>

                <MediaBrowser_Controls:ImageButton VerticalAlignment="Center"				
        				Grid.Column="0" Grid.Row="0"
                        Margin="0,0,5,0"
        				Source="/MediaBrowser.Gui;Component/Images/Backward.png" Command="{Binding BackwardPageCommand}" CommandParameter="{Binding ElementName=book}" Height="30"/>


                <Image Grid.Column="1" Grid.Row="0" Source="/MediaBrowser.Gui;Component/Images/book.png" Stretch="Fill" SizeChanged="Image_SizeChanged" />
                <Viewbox x:Name="VBoxBook" Grid.Column="1" Grid.Row="0" Margin="16,10" Width="Auto" Height="Auto" Stretch="Fill" RenderTransformOrigin="0.5,0.5">
                    <MitsuControls:Book x:Name="book" ItemsSource="{Binding LImgBook}" >
                        <MitsuControls:Book.ItemTemplate>
                            <DataTemplate>
                                <Border BorderThickness="1" BorderBrush="Gray" Background="Transparent">
                                    <Image Source="{Binding .,Converter={StaticResource stringToBitmapConverter}}" Stretch="Fill"/>
                                </Border>
                            </DataTemplate>
                        </MitsuControls:Book.ItemTemplate>
                        <i:Interaction.Triggers>
                            <i:EventTrigger EventName="Loaded">
                                <julmar:InvokeCommand Command="{Binding BookOpenCommand, Mode=Default}" CommandParameter="{Binding ElementName=book}"/>
                            </i:EventTrigger>
                        </i:Interaction.Triggers>
                    </MitsuControls:Book>
                </Viewbox>

                <MediaBrowser_Controls:ImageButton VerticalAlignment="Center"				
        				Grid.Column="2" Grid.Row="0"
                        Margin="5,0,0,0"
        				Source="/MediaBrowser.Gui;Component/Images/Forward.png" Command="{Binding ForwardPageCommand}" CommandParameter="{Binding ElementName=book}" Height="30"/>

                <StackPanel Grid.Row="1" Grid.ColumnSpan="3" HorizontalAlignment="Center" Orientation="Horizontal">
                    <TextBox x:Name="txCurrentPage" VerticalAlignment="Center"  Width="30" Text="{Binding CurrentSheetIndex, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}">
                    </TextBox>
                    <Label VerticalAlignment="Center" Margin="5,0,0,0" Content="{Binding FormatedNavPage}"></Label>
                    <MediaBrowser_Controls:ImageButton x:Name="zoomOut" Content="" Source="/MediaBrowser.Gui;Component/Images/ZoomOut.png" Margin="5,0" Width="20" Height="20"/>
                    <MediaBrowser_Controls:ImageButton x:Name="zoomIn" Content="" Source="/MediaBrowser.Gui;Component/Images/ZoomIn.png" Margin="0,0,5,0" Width="20" Height="20"/>
                </StackPanel>

            </Grid>
        </GroupBox>
        <!-- END CENTER -->

        <!-- ADMIN MOVIES -->
        <Views:UserCtrlAdminBooks x:Name="UserCtrlAdminBooks" Width="500" Height="400" Grid.ColumnSpan="2" Grid.RowSpan="2" RenderTransformOrigin="0.5,0.5" ScrollViewer.HorizontalScrollBarVisibility="Auto" ScrollViewer.VerticalScrollBarVisibility="Auto">
            <Views:UserCtrlAdminBooks.RenderTransform>
                <TransformGroup>
                    <ScaleTransform ScaleX="0" ScaleY="0"/>
                    <SkewTransform/>
                    <RotateTransform/>
                    <TranslateTransform/>
                </TransformGroup>
            </Views:UserCtrlAdminBooks.RenderTransform>
        </Views:UserCtrlAdminBooks>

    </Grid>
</UserControl>
